package pl.donajski.magisterka;

public class Node {
	/**
	 * @param index
	 * @param capacityModuleOpex
	 * @param cpacityModuleSize
	 * @param processingOpex
	 * @param processingRateMax
	 */
	public Node(int index, int capacityModuleOpex, int cpacityModuleSize,
			int processingOpex, int processingRateMax) {
		this.mIndex 				= index;
		this.mCapacityModuleOpex 	= capacityModuleOpex;
		this.mCpacityModuleSize 	= cpacityModuleSize;
		this.mProcessingOpex 		= processingOpex;
		this.mProcessingRateMax 	= processingRateMax;
		this.mAssignmentsCount 		= 0;
	}
	
	@Override
	public String toString() {
		return this.mIndex + "\t" +
			   this.mCapacityModuleOpex + "\t" +
			   this.mCpacityModuleSize + "\t" +
			   this.mProcessingOpex + "\t" +
			   this.mProcessingRateMax;
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj == null)
			return false;
		return ((Node)obj).getIndex() == this.mIndex;
	}
	
	
	
	/**
	 * Gets node's unique index
	 * @return unique index
	 */
	public int getIndex() {
		return mIndex;
	}
	/**
	 * Gets cost of one network capacity module
	 * @return network capacity module cost
	 */
	public int getCapacityModuleOpex() {
		return mCapacityModuleOpex;
	}
	/**
	 * Gets network capacity module size i.e. unit of bandwidth in Mb/s
	 * @return network capacity module size
	 */
	public int getCapacityModuleSize() {
		return mCpacityModuleSize;
	}
	
	/**
	 * Gets cost of processing one unified computing task represented by {@link Task}
	 * @return processing cost
	 */
	public int getProcessingOpex() {
		return mProcessingOpex;
	}
	/**
	 * Gets node's maximum processing rate i. e. maximum number of 
	 * unified tasks represented by {@link Task} that can be assigned to
	 * this node
	 * @return maximum processing rate
	 */
	public int getProcessingRateMax() {
		return mProcessingRateMax;
	}
	/**
	 * Gets node's upload flow rate
	 * @return upload flow rate
	 */
	public int getUFlow() {
		return mUflow;
	}
	/**
	  * Gets node's download flow rate
	  * @return download flow rate
	 */
	public int getDFlow() {
		return mDflow;
	}
	/**
	 * Sets cost of one network capacity module
	 */
	public void setCapacityModuleOpex(int capacityModuleOpex) {
		this.mCapacityModuleOpex = capacityModuleOpex;
	}
	/**
	 * Sets network capacity module size i.e. unit of bandwidth in Mb/s
	 */
	public void setCapacityModuleSize(int capacityModuleSize) {
		this.mCpacityModuleSize = capacityModuleSize;
	}
	/**
	 * Sets cost of processing one unified computing task represented by {@link Task}
	 */
	public void setProcessingOpex(int processingOpex) {
		this.mProcessingOpex = processingOpex;
	}
	/**
	 * Sets node's maximum processing rate i. e. maximum number of 
	 * unified tasks represented by {@link Task} that can be assigned to
	 * this node
	 */
	public void setProcessingRateMax(int processingRateMax) {
		this.mProcessingRateMax = processingRateMax;
	}
	/**
	 * Sets node's upload flow rate
	 * @param uFlow upload flow to be set
	 */
	public void setUFlow(int uFlow) {
		this.mUflow = uFlow;
	}
	/**
	 * Sets node's download flow rate
	 * @param uFlow download flow to be set
	 */
	public void setDFlow(int dFlow) {
		this.mDflow = dFlow;
	}
	/**
	 * @return the mAssignmentsCount
	 */
	public int getAssignmentsCount() {
		return mAssignmentsCount;
	}
	/**
	 * increments assignment count
	 */
	public void addAssignement() {
		this.mAssignmentsCount++;
	}

	/**
	 * decrements assignment count
	 */
	public void removeAssignement() {
		this.mAssignmentsCount--;
	}
	
	/**
	 * Checks whether node processingMax is enough for processing assigned tasks
	 * @return true if node is valid, false otherwise
	 */
	public boolean isValid() {
		return this.mProcessingRateMax >= this.mAssignmentsCount;
	}
	
	/**
	 * Checks whether node processingMax is enough for processing another task
	 * @return true if node will be valid after next assignment, false otherwise
	 */
	public boolean canAssign() {
		return this.mProcessingRateMax > this.mAssignmentsCount;
	}
	
	public int getCost() {
		return this.mAssignmentsCount * this.mProcessingOpex;
	}
	
	public int getValidness() {
		return Math.max(this.mAssignmentsCount - this.mProcessingRateMax, 0);
	}

	

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return this.mIndex;
	}



	private int mIndex;
	private int mCapacityModuleOpex;
	private int mCpacityModuleSize;
	private int mProcessingOpex;
	private int mProcessingRateMax;
	private int mUflow;
	private int mDflow;
	private int mAssignmentsCount;
}
